%% Make Up Data for VAR Estimation
% by Jaromir Benes
%
% In this file, we generate three random series, and call them `R`,
% `PI`, and `Y` (for interest rates, inflation, and output). The series
% will be used to estimate a SVAR with sign restrictions.

%% Clear Workspace

clear;
close all;
clc;

%% Generate and tweak random data
%
% Use a random number generator and Hodrick-Prescott filter to create fake
% series called `R` (for an interest rate), `PI` (for inflation), and `Y`
% (for real economic activity such as the output gap or output growth).
% These series are then used to estimate a VAR.

range = qq(1990,1) : qq(2015,4);

d = struct();

d.R = tseries(range,@rand);
d.PI = tseries(range,@rand);
d.Y = tseries(range,@rand);

d = dbfun(@cumsum,d);
d = dbfun(@(x) hpf2(x,Inf,'lambda=',1600),d);

%% Plot the data

dbplot(d,range,{'R','PI','Y'}, ...
    'tight=',true,'dateformat=',{'YYYY:P','YY:P'},'zeroline=',true);
ftitle('Remember, these are made-up data... not real!');

%% Save data in CSV
%
% Use the function `dbsave` to save the data to a CSV (text-oriented) file.
% The data could be, alternatively, saved to a mat file (which would be
% more efficient) using the standard `save` command,
%
%    save make_up_data.mat d;
%
% Tha advantage of CSV files is that they can be viewed by spreadsheet
% programs (such as MS Excel), and easily exported to other software
% packages.

dbsave(d,'VAR_Sign_Restrict_Data.csv');

%% Help on IRIS Functions Used in This File
%
% Use either `help` to display help in the command window, or `idoc`
% to display help in an HTML browser window.
%
%    help tseries/tseries
%    help data/dbfun
%    help data/dbplot
%    help grfun/ftitle
%    help data/dbsave
